package com.performax.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.performax.database.Vo.*;
import com.performax.database.Dao.*;
import com.performax.utils.*;


@Controller
@RequestMapping("/app/api/login")
public class OheGameLoginController {
	
	private static final Logger logger = LoggerFactory.getLogger(OheGameLoginController.class);
	
	@Resource(name = "oh2gameAdDao")
	private Oh2GameAdDao oh2gameAdDao;
	
	@Resource(name = "oh2gameGlobalDao")
	private Oh2GameGlobalDao oh2gameGlobalDao;
	
	
	@RequestMapping(value="/getbilist")
	@ResponseBody
	public Object getbilist(HttpServletRequest req){
		

		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		
		List<BiInfoVo> biInfo	=	oh2gameAdDao.getBiList();
		AppInfoVo appInfo	=	oh2gameGlobalDao.getAppInfo();
		
		result.put("resType", "getbilist");
		result.put("result", "1000");
		result.put("resultMessage", "success");
		result.put("thumbNailUrl", appInfo.getAppThumbNailUrl());
		result.put("listCnt", biInfo.size());
		result.put("biInfo", biInfo);
		
		logger.debug("/getbilist", result);
		
		return result;
		
	}
	
	/**
	 * 
	 * @param id
	 * @param pw
	 * @param phone
	 * @param appVer
	 * @param os
	 * @param osVer
	 * @param req
	 * @return
	 * 
	 * process
	 * 1. log save
	 * 2. get userinfo from id
	 * 3. compare password
	 * 4. save login log
	 * 5. return result
	 * 
	 */
	@RequestMapping(value="/login")
	@ResponseBody
	public Object login(@RequestParam(value="id", required=true) String id 
						,@RequestParam(value="pw", required=true) String pw 
						,@RequestParam(value="phone", required=true) String phone
						,@RequestParam(value="appVer", required=true) String appVer
						,@RequestParam(value="os", required=false) String os
						,@RequestParam(value="osVer", required=false) String osVer
						,@RequestParam(value="pushKey", defaultValue="") String pushKey
						,@RequestParam(value="regId", defaultValue="") String regId
						,HttpServletRequest req )
	{
		
		System.out.println("pushKey : "+pushKey);
		System.out.println("regId : "+regId);
		
		HashMap<String, Object> param	=	new	HashMap<String, Object> ();
		param.put("userId", id);
		param.put("pw", pw);
		param.put("phone", phone);
		param.put("appVer", appVer);
		param.put("os", os);
		param.put("osVer", osVer);
		param.put("pushKey", pushKey);
		
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType", "login");
		//* 1. log save
		
		//* 2. get userinfo from id
		AccountInfoVo	accountInfo	=	oh2gameGlobalDao.getAccountInfo(id);
		
		//user id is not exist
		if(accountInfo	==	null){
			result.put("result", "9897");
			result.put("resultMessage", "일치하는 계정이 없습니다. 확인후 다시 로그인 해 주세요.");
			return result;
		}
		
		String		authStatus	=	oh2gameGlobalDao.getAccountAuthMailInfo(id);
		if(authStatus.equals("S")){
			result.put("result", "9776");
			result.put("resultMessage", "이메일 인증이 완료 되지 않았습니다. 이메일 인증을 진행해 주세요.");
			return result;
		}
		
		
		AppInfoVo appInfo	=	oh2gameGlobalDao.getAppInfo();
		
		//* 3. compare password/appVer/os/osVer
		if(!pw.equals(accountInfo.getUserPswd())){
			result.put("result", "9896");
			result.put("resultMessage", "비밀번호가 일치 하지 않습니다.");
			return result;
		}
		
		/*
		result.put("resultMessage", "not supported os");
		
		result.put("resultMessage", "not supported os version");
		
		result.put("resultMessage", "invalid app version");
		
		result.put("resultMessage", "incorrect user id");
		
		result.put("resultMessage", "incorrect password");
		*/
		
		String	aKey		=	"";
		List<UserAuthInfoVo> authKeyInfoList	=	oh2gameGlobalDao.getAccountAuthkey(param);
		//authKey.put("userId", id);
		if(authKeyInfoList	==	null){
			result.put("result", "9896");
			result.put("resultMessage", "not exist auth info");
			return result;
		}
		
		boolean	bAuthPass	=	false;
		for(UserAuthInfoVo	authInfo : authKeyInfoList){
			if(authInfo.getPhone()	==	null)	continue;
			if(authInfo.getPhone().equals(phone)){
				HashMap<String, Object> authKeyInfo	=	new	HashMap<String, Object>();
				aKey	=	authInfo.getAuthKey();
				if(authInfo.getAuthKey()	==	null	||	authInfo.getAuthKey().equals("")	||	(!authInfo.getAuthKey().equals(""))){
					aKey	=	Oh2gameUtils.getAuthKey(id, phone);
					authKeyInfo.put("userId", id);
					authKeyInfo.put("authKey",aKey );
					authKeyInfo.put("phone", phone);
					authKeyInfo.put("regId", regId);
					oh2gameGlobalDao.updAuthKey(authKeyInfo);
				}else{
					authKeyInfo.put("userId", id);
					authKeyInfo.put("regId", regId);
					oh2gameGlobalDao.updAuthKeyExpireDt(authKeyInfo);
				}
				
				bAuthPass	=	true;
			}
		}
		
		if(bAuthPass	==	false){
			HashMap<String, Object> authKeyInfo	=	new	HashMap<String, Object>();
			aKey	=	Oh2gameUtils.getAuthKey(id, phone);
			authKeyInfo.put("userId", id);
			authKeyInfo.put("authKey", aKey);
			authKeyInfo.put("phoneNo", phone);
			authKeyInfo.put("regId", regId);
			authKeyInfo.put("gaid", "XXXXXXXXXX");
			
			oh2gameGlobalDao.regUserDevice(authKeyInfo);
		}
		
		
		//if all clear
		result.put("result", 		"1000");
		result.put("resultMessage", "success");
		result.put("authKey", 		aKey);
		result.put("nickname", 		accountInfo.getUserNickname());
		result.put("id", 			accountInfo.getUserId());
		result.put("gender", 		accountInfo.getUserGender());
		result.put("birth", 		accountInfo.getUserBirth());
		result.put("genre", 		accountInfo.getUserGenre());
		result.put("age", 			Oh2gameUtils.getAge(accountInfo.getUserBirth()));
		result.put("pushKey", 		pushKey);
		result.put("profileUrl", 	accountInfo.getProfileUrl());
		//update authKey field at user db
		
		
		//* 4. save login log
		
		//* 5. return result
		
		result.put("resType", "login");
		
		/*if(id.equals("9991")){
			result.put("result", "9991");
			result.put("resultMessage", "not supported os");
			
		}else if(id.equals("9992")){
			result.put("result", "9992");
			result.put("resultMessage", "not supported os version");
			
		}else if(id.equals("9993")){
			result.put("result", "9993");
			result.put("resultMessage", "invalid app version");
			
		}else if(id.equals("9897")){
			result.put("result", "9897");
			result.put("resultMessage", "incorrect user id");
			
		}else if(id.equals("9896")){
			result.put("result", "9896");
			result.put("resultMessage", "incorrect password");
			
		}else{
			result.put("result", "1000");
			result.put("resultMessage", "success");
			result.put("authKey", "sad9009asdf");
		}	*/
		
		
		
		logger.debug("/login", result);
		return result;
		
	}
	
	/**
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value="/findaccount")
	@ResponseBody
	public Object findAccount(	@RequestParam(value="type", required=true) String type 
								,@RequestParam(value="id", required=false) String id
								,@RequestParam(value="phone", required=true) String phone
								,@RequestParam(value="authNo", required=true) String authNo
								,HttpServletRequest req )
	{
		/**
		 * 1. req from client
		 * 2. compare id/phone/authNo
		 * 3. if all clear - getTempPswd save  
		 * 
		 */
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","findaccount");
		
		
		AccountInfoVo	accountInfo	=	oh2gameGlobalDao.getAccountInfo(id);
		
		if(accountInfo	==	null){
			result.put("result","9999");
			result.put("resultMessage","invalid phone no");
			
			return result;
		}
		
		result.put("result", "1000");
		
		//check Type
		if(type.equals("id")){
			result.put("type", "id");
			result.put("id", accountInfo.getUserId());
		}else{	//if success
			
			String tempPw	=	Oh2gameUtils.genTempPswd();
			
			//set temp pw to user table
			HashMap<String, Object> tmpParam	= new	HashMap<String, Object>();
			tmpParam.put("password", tempPw);
			tmpParam.put("userId", id);
			oh2gameGlobalDao.updatePassword(tmpParam);
			
			result.put("type", "pw");
			result.put("pw", tempPw);
			
		} 
		result.put("resultMessage", "success");
		
		/*if(id.equals("9999")){
			result.put("result","9999");
			result.put("resultMessage","invalid phone no");
		}
		result.put("result","1000");
		result.put("resultMessage","success");
		result.put("type", type);
		result.put("id","oh2game");
		if(type.equals("pw")){
			result.put("pw","oh2gamepassword!");
		}*/
		
		Hashtable<String, String> param	=	new	Hashtable<String, String>();
		
		param.put("id", type);
		param.put("pw", id);
		param.put("phone", phone);
		param.put("appVer", authNo);
		
		
		result.put("resultMessage", param);
		
		logger.debug("/findaccount", result);
		return result;
	}
	
	@RequestMapping(value="/checkdupid")
	@ResponseBody
	public Object checkdupid(	 
						@RequestParam(value="id", required=true) String id
						,HttpServletRequest req )
	{
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","checkdupid");
		
		int userExist	=	oh2gameGlobalDao.checkExistUser(id);
		
		if(userExist	>	0){
			
			result.put("result","2998");
			result.put("resultMessage","이미 사용중인 ID 입니다.");
			return result;
		}
		result.put("result","1000");
		result.put("resultMessage","success");
		
		return result;
	}
	
	@RequestMapping(value="/join")
	@ResponseBody
	public Object join(	 @RequestParam(value="mediaCd", required=false) String mediaCd 
						,@RequestParam(value="gid", required=false) String gid
						,@RequestParam(value="id", required=true) String id
						,@RequestParam(value="nick", required=true) String nick
						,@RequestParam(value="pswd", required=true) String pswd 
						,@RequestParam(value="phone", required=false) String phone
						,@RequestParam(value="authNo", required=true) String authNo
						,@RequestParam(value="birth", required=true) String birth
						,@RequestParam(value="gender", required=true) String gender
						,@RequestParam(value="genre", required=true) String genre
						,@RequestParam(value="pushKey",required=false) String pushKey
						,HttpServletRequest req )
	{
		long callTime	=	System.currentTimeMillis();
		String	callStamp	=	"["+callTime+"]";
		System.out.println("call start"+callStamp);
		
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		
		AccountInfoVo	accountInfo	=	new	AccountInfoVo();
		accountInfo.setUserId(id);
		accountInfo.setUserNickname(nick);
		accountInfo.setUserPswd(pswd);
		accountInfo.setPhone(phone);
		accountInfo.setUserBirth(birth);
		accountInfo.setUserGender(gender);
		accountInfo.setUserGenre(genre);
		accountInfo.setUserEncTp("N");
		result.put("resType","join");
		
		int userExist	=	oh2gameGlobalDao.checkExistUser(id);
		System.out.println("existCnt : ["+userExist+"]");
		if(userExist	>	0){
			
			result.put("result","2998");
			result.put("resultMessage","이미 사용중인 ID 입니다.");
			System.out.println(1+" : call start"+callStamp);
			return result;
			
		}
		System.out.println(2+" : call start"+callStamp);
		
		//sms 인증번호 확인 
		HashMap<String, Object>	authInfo	=	oh2gameGlobalDao.getAuthNo(phone);
		if(authInfo	==	null){
			result.put("result", "9899");
			result.put("resultMessage", "SMS 인증번호 오류.");
			return result;
		}else{
			long expireTime	=	((Date)authInfo.get("expireDt")).getTime();//Oh2gameUtils.getCurrentTime((Date)authInfo.get("expireDt"), Oh2gameUtils.FORMAT_YYYY_MM_DD_HH_MIN_SS);
			long currTime	=	System.currentTimeMillis();
			if(expireTime < currTime){
				result.put("result", "9898");
				result.put("resultMessage", "SMS 인증번호 입력시간 초과");
				return result;
			}
			
			if(!authInfo.get("authNo").equals(authNo)){
				result.put("result", "9899");
				result.put("resultMessage", "SMS 인증번호 오류.");
				return result;
			}
		}
		
		
		/*DeviceVo	deviceInfo	=	new	DeviceVo();
		deviceInfo.setDeviceGoogleAdId(gid);
		deviceInfo.setDevicePhoneNo(phone);*/ 
		
		HashMap<String, Object>	hUserDeviceInfo	=	new	HashMap<String, Object>();
		hUserDeviceInfo.put("userId", id);
		hUserDeviceInfo.put("regId", pushKey);
		hUserDeviceInfo.put("gaid", gid);
		hUserDeviceInfo.put("phoneNo", phone);
		//hUserDeviceInfo.put("authKey", );
		//hUserDeviceInfo.put("sessinoExpireTerm", Oh2gameUtils.SESSION_EXPIRE_TERM_HOUR);
		
		
		System.out.println(3+" : call start"+callStamp);
		
		
		//String status	=	callUrl("performax/app/api/login/sendmail?id="+id);
		
		HashMap<String, Object> emailInfo	=	oh2gameGlobalDao.getEmailAuthInfo(id);
		
		oh2gameGlobalDao.insertEmailAuthInfo(emailInfo);
		
		//if(status.equals("success")){
		oh2gameGlobalDao.regAccount(accountInfo, hUserDeviceInfo);
		oh2gameGlobalDao.completeSmsAuth(phone, authNo);
			
		result.put("result","1000");
		result.put("resultMessage","success");
		
		System.out.println(5+" : call start"+callStamp);
		
		
		/*Hashtable<String, String> param	=	new	Hashtable<String, String>();
		
		param.put("mediaCd", mediaCd);
		param.put("gid", gid);
		param.put("id", id);
		param.put("nick", nick);
		param.put("pswd", pswd);
		param.put("phone", phone);
		//param.put("authNo", authNo);
		param.put("birth", birth);
		param.put("gender", gender);
		param.put("genre", genre);
		
		
		result.put("resultMessage", param);*/
		
		System.out.println(6+" : call start"+callStamp);
		
		logger.debug("/join", result);
		return result;

	}
	
	@RequestMapping(value="/checkdupnick")
	@ResponseBody
	public Object checkdupnick(	 @RequestParam(value="mediaCd", required=false) String mediaCd 
								,@RequestParam(value="gid", required=false) String gid
								,@RequestParam(value="nick", required=true) String nick
								,HttpServletRequest req )
	{

		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","checkdupnick");
		
		if(nick.equals("2999")){
			result.put("result","2999");
		}else{
			result.put("result","1000");
		}
		
		
		HashMap<String, Object> param	=	new	HashMap<String, Object>();
		
		param.put("mediaCd", mediaCd);
		param.put("gid", gid);
		param.put("nick", nick);
		
		int count	=	oh2gameGlobalDao.checkDuplicateNickName(param);
		
		if(count	>	0){
			result.put("result", "2999");
		}
		
		result.put("resultMessage", param);
		
		logger.debug("/chekcdupnick", result);
		return result;

	}
	
	@RequestMapping(value="/sendauth")
	@ResponseBody
	public Object sendauth(  @RequestParam(value="mediaCd", required=false) String mediaCd 
							,@RequestParam(value="gid", required=false) String gid
							,@RequestParam(value="phone", required=true) String phone
							,@RequestParam(value="type", defaultValue="JOIN") String type
							,HttpServletRequest req )
	{
		long				expireTerm	=	1000*60*5;	//5 minute
		Date				expireDt	=	new	Date(System.currentTimeMillis()+expireTerm);
		SimpleDateFormat	format		=	new	SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String				validDate	=	format.format(expireDt);

		String 	authNo			=	Oh2gameUtils.getAuthNo();
		
		HashMap<String, Object> param			=	new	HashMap<String, Object>();
		
		param.put("mediaCd"	, mediaCd);
		param.put("gid"		, gid);
		param.put("userId"	, phone);
		param.put("phone"	, phone);
		param.put("authKey"	, 	authNo);
		param.put("authType", 	"AUTH_SMS");
		param.put("expireDt",	validDate);
		
		param.put("callBackNo", oh2gameGlobalDao.getFileSavePath("SMS_CALLBACK_NO"));
		String	message	=	oh2gameGlobalDao.getFileSavePath("SMS_AUTH_MESSAGE");
		
		
		if(type.equals("FIND")){
			message	=	message.replaceAll("smsAuthTypesms", "이메일/비밀번호찾기");
		}else if(type.equals("PCHG")){
			message	=	message.replaceAll("smsAuthTypesms", "번호변경");
		}else{
			message	=	message.replaceAll("smsAuthTypesms", "회원가입");
		}
			
		message	=	message.replaceAll("smsAuthNosms", authNo);
		
		param.put("message", message);
		
		oh2gameGlobalDao.insertSmsAuthNo(param);
		
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","sendauth");
		result.put("result","1000");
		
		result.put("resultMessage", param);
		logger.debug("/sendauth", result);
		return result;

	}
	
	/*@RequestMapping(value="/sendmail")
	@ResponseBody
	public String sendmail(@RequestParam(value="id", required=true) String id
							,HttpServletRequest req )
	{
		
		HashMap<String, Object> emailInfo	=	oh2gameGlobalDao.getEmailAuthInfo(id);
		System.out.println("mail1");
		email.setContents((String)emailInfo.get("contents"));
		email.setReceiver(id);
		email.setSubject((String)emailInfo.get("title"));
		System.out.println("mail2");
		
		try{
			System.out.println("emailSender :"+emailSender);
			System.out.println("email :"+email);
			emailSender.SendEmail(email);
			System.out.println("authentication mail send complete!!");
		}catch(Exception e){
			e.printStackTrace();
			return  "{\"status\":\"fail\"}";
		}
		oh2gameGlobalDao.insertEmailAuthInfo(emailInfo);
		
		return "{\"status\":\"success\"}";
	}
	
	public String	callUrl(String path){
		
		String url	=	"http://localhost:8080/"+path;
		CloseableHttpClient	httpClient	=	HttpClients.createDefault();
		HttpGet				httpGet		=	new	HttpGet(url);
		String resultMessage	=	"200";
		try{
			CloseableHttpResponse response	=	httpClient.execute(httpGet);
			try{
				HttpEntity entity	=	response.getEntity();
				if(response.getStatusLine().getStatusCode()	==	HttpServletResponse.SC_OK){
					ObjectMapper	objMap	=	new	ObjectMapper();
					
					HashMap<String, Object>	result	=	objMap.readValue(EntityUtils.toString(entity), HashMap.class);
					
					return (String)result.get("status");
				}else{
					
				}
				
				EntityUtils.consume(entity);
			}finally{
				response.close();
			}
		}catch(Exception e){
			e.printStackTrace();
			httpGet.releaseConnection();
			
		}
		return "fail";
		
	}
	*/
	
	@RequestMapping(value="/sdklogin")
	@ResponseBody
	public Object sdklogin(	 @RequestParam(value="mediaCd", defaultValue="") String mediaCd 
						,@RequestParam(value="gid", required=true) String gid
						,@RequestParam(value="id", required=true) String id
						,@RequestParam(value="nick", defaultValue="") String nick
						,@RequestParam(value="authKey", defaultValue="") String authKey
						,@RequestParam(value="birth", defaultValue="1980-01-01 00:00:00") String birth
						,@RequestParam(value="gender", defaultValue="M") String gender
						,@RequestParam(value="phone", defaultValue="01012341234") String phone
						,HttpServletRequest req )
	{
		/*
		 * id, mediaCd 를 이용하여 사용자 조회
		 * 
		 * 사용자 조회될 경우 
		 * - authKey 조회
		 * - authKey 유효할 경우 ( expire time 연장)
		 * - authKey 유효하지 않을 경우 (신규 authKey 생성)
		 * 
		 * 
		 * 사용자 조회되지 않을경우
		 * - nick name 중복 여부 확인 
		 * - 사용자 정보 등록
		 * - 
		 * 
		 */
		
		String userId	=	new	StringBuffer().append(mediaCd).append("_").append("id").toString();
		if(phone.equals("")){
			phone	=	mediaCd;
		}
		String	newAuthKey	=	"";
		
		HashMap<String, Object> userParam	=	new	HashMap<String, Object>();
		userParam.put("userId", id);
		userParam.put("mediaCd", mediaCd);
		AccountInfoVo	accountInfo	=	oh2gameGlobalDao.getSdkAccountInfo(userParam);
		
		
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","sdklogin");
		
		if(accountInfo	!=	null){
			//getAuthKey by userid, mediaCd
			
			List<UserAuthInfoVo> authKeyList	=	oh2gameGlobalDao.getSdkAccountAuthkey(userParam);
			
			boolean	existAuthKey	=	false;
			for(int i = 0; i < authKeyList.size() ; i++){
				UserAuthInfoVo authKeyInfo	=	authKeyList.get(i);
				if(authKeyInfo.getAuthKey().equals(authKey)){
					if(authKeyInfo.getExpireDt()	>	(System.currentTimeMillis()/1000)){
						//update expireTime
						userParam.put("authKey", authKeyInfo.getAuthKey());
						newAuthKey	=	authKeyInfo.getAuthKey();
						oh2gameGlobalDao.updAuthKeyExpireDt(userParam);
						existAuthKey	=	true;
					}
				}
			}
			
			
			if(existAuthKey	==	false){
				newAuthKey	=	Oh2gameUtils.getAuthKey(id, phone);
		    	userParam.put("phone", phone);
		    	userParam.put("authKey", newAuthKey);
		    	userParam.put("phone",	mediaCd);
		    	userParam.put("regId", "");
		    	oh2gameGlobalDao.updAuthKey(userParam);
			}
			
			
			if(!nick.equals(accountInfo.getUserNickname())){	//
				HashMap<String, Object> checkParam	=	new	HashMap<String, Object>();
				checkParam.put("gid", gid);
				checkParam.put("nick", nick);
				int count	=	oh2gameGlobalDao.checkDuplicateNickName(checkParam);
				if(count	>	0){	//check nick duplicate	
					result.put("resultCode","login_9001");
					result.put("result","login_9001");
				}else{
					accountInfo.setUserNickname(nick);
					oh2gameGlobalDao.changeNickName(accountInfo);
					result.put("authKey", newAuthKey);
					result.put("resultCode","login_1000");
					result.put("result","login_1000");
					
				}
			}else{
				result.put("authKey", newAuthKey);
				result.put("resultCode","login_1000");
				result.put("result","login_1000");
			}
			
		}else{
			accountInfo	=	new	AccountInfoVo();
			accountInfo.setUserId(id);
			accountInfo.setUserNickname(nick);
			accountInfo.setUserPswd(id);
			accountInfo.setUserBirth(birth);
			accountInfo.setUserGender(gender);
			accountInfo.setMediaCd(mediaCd);
			accountInfo.setUserGenre("");
			accountInfo.setUserEncTp("N");
			
			newAuthKey	=	Oh2gameUtils.getAuthKey(id, phone);
			//SDK 사용자의 경우 push 및 phone 번호 전달이 필요 없음
			HashMap<String, Object>	hUserDeviceInfo	=	new	HashMap<String, Object>();
			hUserDeviceInfo.put("userId", id);
			hUserDeviceInfo.put("regId", "");			
			hUserDeviceInfo.put("gaid", gid);
			hUserDeviceInfo.put("phoneNo", mediaCd);
			hUserDeviceInfo.put("authKey", newAuthKey);
			
			HashMap<String, Object> checkParam	=	new	HashMap<String, Object>();
			checkParam.put("gid", gid);
			checkParam.put("nick", nick);
			int count	=	oh2gameGlobalDao.checkDuplicateNickName(checkParam);
			
			
			
			if(count	>	0){	//check nick duplicate	
				result.put("resultCode","join_9001");
				result.put("result","join_9001");
			}else{
				oh2gameGlobalDao.regSdkAccount(accountInfo, hUserDeviceInfo);
				result.put("resultCode","join_1000");
				result.put("result","join_1000");
				result.put("authKey", newAuthKey);
			}
			
		}
		
		return result;
		

	}

	
}
